<?php

namespace app\api\controller\question;

use app\api\model\question\Question as QuestionModel;
use app\api\controller\Controller;
use app\api\model\course\Category as CategoryModel;
use app\api\model\page\Ad as AdModel;
use app\api\model\examination\ExaminationUserAward;

/**
 * 题库控制器
 */
class Question extends Controller
{



    /**
     * 题库列表
     */
    public function index()
    {
        // 获取列表数据
        $model = new QuestionModel;
        $category = CategoryModel::getList();
        $list=$model->getQuestion($category,$this->getUser());
        $AdModel=new AdModel;
        $ad=$AdModel->getList();
        $ExaminationUserAward=new ExaminationUserAward;
        $user_award=$ExaminationUserAward->getArr();
        return $this->renderSuccess('', compact('list','ad','user_award'));
    }

    /**
     * 题库列表
     */
    public function list()
    {
        // 获取列表数据
        $model = new QuestionModel;
        $data = $this->getData();
        $list = $model->getList($data, $this->getUser());
        //加入缓存

        return $this->renderSuccess('', $list);
    }

    //提交答案
    public function submitAnswer()
    {
        $model = new QuestionModel;
        if ($model->submitAnswer($this->postData(),$this->getUser())) {
            return $this->renderSuccess('提交成功');
        } else {
            return $this->renderError($model->getError() ?: '提交失败');
        }
    }


    /**
     * 题库详情
     */
    public function detail($hire_id)
    {
        // 获取列表数据
        $model = new QuestionModel;
        $detail = $model->getDetail($hire_id, $this->getUser(false));
        return $this->renderSuccess('', compact('detail'));
    }

    /**
     * 题库章节详情
     */
    public function sectionDetail()
    {
        $user = $this->getUser(false);
        // 获取列表数据
        $model = new CourseSectionModel;
        $detail = $model->getDetail($this->postData(), $user);
        if ($detail) {
            return $this->renderSuccess('', compact('detail'));
        } else {
            return $this->renderError($model->getError() ?: '查看失败');
        }
    }
}